import { defineStore } from 'pinia'
import axios from 'axios'
import { ChannelsRes, Channels } from '../../types/data'

export default defineStore('channel', {
  state() {
    return {
      curId: 0, // 当前选中的频道的id
      channels: [] as Channels
    }
  },
  actions: {
    setCurId(newCurId: number) {
      this.curId = newCurId
    },
    async getChannel() {
      const res = await axios.get<ChannelsRes>('http://geek.itheima.net/v1_0/channels')
      console.log(res.data.data.channels)
      this.channels = res.data.data.channels
      this.curId = this.channels[0].id
    }
  }
})